package com.itheima.thread.communication.demo04;

import java.util.concurrent.locks.ReentrantLock;

public class ProducerThread implements Runnable {

    private Box box;
    private ReentrantLock reentrantLock;
    public ProducerThread(Box box, ReentrantLock reentrantLock) {
        this.box = box;
        this.reentrantLock = reentrantLock;
    }

    private int count = 0;

    @Override
    public void run() {

        while (true) {

            reentrantLock.lock();

            if(count %2 == 0) {
                box.setMilkType("牛奶");
                box.setAmount("5L");
            }else{
                box.setMilkType("羊奶");
                box.setAmount("10L");
            }

            reentrantLock.unlock();

            count++;

        }

    }
}
